package com.share.hope.controller;

import com.share.hope.entity.PoorChildren;
import com.share.hope.entity.page.PageQueryVo;
import com.share.hope.entity.result.PageR;
import com.share.hope.entity.result.R;
import com.share.hope.service.PoorChildrenService;
import com.share.hope.vo.PoorChildPageQueryVo;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/share/hope/pool_child")
@RequiredArgsConstructor
@CrossOrigin
@Tag(name = "贫困儿童信息管理接口")
public class PoorChildrenController {

    private final PoorChildrenService poorChildrenService;

    @PostMapping("/save")
    @Operation(summary = "存储信息")
    public R<String> savePoorChildren(@RequestBody PoorChildren poorChildren) {
        return poorChildrenService.savePoorChildren(poorChildren);
    }

    @PostMapping("/update")
    public R<String> updatePoorChildren(@RequestBody PoorChildren poorChildren) {
        return poorChildrenService.updatePoorChildren(poorChildren);
    }

    @GetMapping("/delete")
    public R<String> deletePoorChildren(@RequestParam Long id) {
        return poorChildrenService.deletePoorChildren(id);
    }

    @PostMapping("/page")
    @Operation(summary = "分页查询")
    public R<PageR<PoorChildren>> pagePoorChildren(@RequestBody PageQueryVo<PoorChildPageQueryVo> queryVo) {
        return poorChildrenService.pagePoorChildren(queryVo);
    }

    @GetMapping("/by_id")
    @Operation(summary = "根据id查询，用来展示详情")
    public R<PoorChildren> getPoorChildrenById(@RequestParam Long id) {
        return poorChildrenService.getPoorChildrenById(id);
    }

    @GetMapping("/get_all")
    @Operation(summary = "返回全量数据用来购买商品时展示儿童")
    public R<List<PoorChildren>> getAllPoorChildren(@RequestParam(required = false) Long userId) {
        return poorChildrenService.getAllPoorChildren(userId);
    }

}
